function analyzebeta
disp '==================='

subjects = {'LD','TA','MJ','MM','TJ','TJFCD','TK'};
subjects = {'LD','TA','MJ','MM','TJ'};
%subjects = {'MM'};

saveresults=[];

savefolder = ['bfig'];

timecourses = {'BetaAtypicalWantedvsUnwantedTimecourse'};
%timecourse = 'BetaAtypicalWillCWvsCCWTimecourse';
%timecourses = {'BetaAtypicalhrfbinHoldSwitchTimecourse','BetaAtypicalhrfbinWantedTimecourse','BetaAtypicalhrfbinStateTimecourse'};

for n=1:length(timecourses)
    
timecourse = timecourses{n};
[g gg ggg]=mkdir(savefolder);

file2=[];
file2names=[];

for SUB=subjects
    
    clear ('results','data','goodpred','Testrunlogical','cfg');
    load(['C:/Users/Yoren/Desktop/SVM/SVM Gijs/' SUB{1} '/SVM Results/ROIs 08-Jul-2010.mat']);
    disp(['subject ' SUB{1} ', timecourse ' timecourse]);
    
    for ROI=1:size(cfg.ROIs,2)
        disp (['ROI ' num2str(ROI) ': ' results{ROI}.ROI]);

        goodpred = [];

        for SVMpass = 1:cfg.SVMruns %1:size(results{ROI}.LLvsLRTimecourse.TestrunsIndex{1},2)

            %testrunlogical bevat 1en voor de trainingruns and 0en voor de testruns.
            %disp  (cfg.SVMruns);
            Testrunlogical=ones(size(results{ROI}.(timecourse).usedTimecourse{SVMpass}));
            Testrunlogical(:,results{ROI}.(timecourse).TestrunsIndex{SVMpass}) = 0;

            predicted = results{ROI}.(timecourse).testprediction{SVMpass};
            expected = results{ROI}.(timecourse).usedTimecourse{SVMpass}(logical(Testrunlogical));

            goodpred(end+1) = (sum(predicted==expected)/size(predicted,1));
            
            disp(results{ROI}.(timecourse).SVMAccuracies);
            
            %results{ROI}.BetaAtypicalWantedvsUnwantedTimecourse.SVMAccuracies zou  ook gewoon goodpred berekenen,  maar
            %dan en stuk korter dus. maar dan heb je geen stdevs
        end
        
         disp (['goed = ' num2str(mean(goodpred)) ' +/- ' num2str(std(goodpred))]);
         saveresults.mean.(SUB{1})(ROI) = mean(goodpred);
         saveresults.std.(SUB{1})(ROI) = std(goodpred);
         saveresults.ROIs.(SUB{1}){ROI} = results{ROI}.ROI;
         
         file2(end+1,:) = goodpred;
         file2names{end+1} = [SUB{1} '-' results{ROI}.ROI];
    end
end

figure;
title('hoi')
for i=1:size(subjects,2)
     subplot(ceil(size(subjects,2)/2),2,i);
     errorbar(saveresults.mean.(subjects{i})',saveresults.std.(subjects{i}));
     hold on
     plot([0 size(saveresults.ROIs.(subjects{i}),2)+1],[0.5 .5],'r'); 
     title('timecourse');
     
     set(gca,'FontSize',5);
     
     set(gca,'XTick',1:size(saveresults.ROIs.(subjects{i}),2));
     set(gca,'XTickLabel',saveresults.ROIs.(subjects{i}));
 
     title(['subject ' subjects{i}]);
     
     %legend('Shuffled','Non-shuffled','Location','EastOutside');
end
 
text(0,0,'');
subplot('Position',[0 0.0 1 0.05])
axis off;
text(0.05,0.7,['Experiment: ' cfg.experiment{1} ', analysistype: ' cfg.analysistype{1} ', Timecourse: ' timecourse],'FontSize',7);
text(0.05,0.2,['timestarted: ' cfg.timestarted],'FontSize',7);

disp(['saving plot: ' savefolder  '/' timecourse '.pdf']);
saveas(gcf,[savefolder '/' timecourse '.pdf']);
 
disp(saveresults);

disp(saveresults.ROIs);

allrois = {'V1'  'V2'  'V3'  'V3A'  'V4D' 'V4V' 'V7'  'VP'  'MT'  'AIPS'  'PIPS'  'V4V'  'FEF'  'SEF'};
file1=zeros(size(allrois,2),size(subjects,2));
for y=1:size(subjects,2)
    for x=1:size(allrois,2)
        for r = 1:size(saveresults.ROIs.(subjects{y}),2);
            if strcmp(saveresults.ROIs.(subjects{y})(r),allrois(x))
                file1(x,y) = saveresults.mean.(subjects{y})(r);
            end
        end
    end
end   
disp(file1');

disp (subjects');
disp (file2names');
dlmwrite('meanpersubject.txt',file1','newline','pc','delimiter','\t');
%dlmwrite('subjectsnames.txt',subjects);
%dlmwrite('roinames.txt',allrois);

dlmwrite('resultsperroi.txt',file2','newline','pc','delimiter','\t');
%dlmwrite('roinames2.txt',file2names);
end
end

% function alles = allesopeenhoop(varin)
%     if length(varin) > 1 || isa(varin,'struct')
%         alles = cell(1,size(varin(:)));
%         for l = 1:size(varin(:))
%             alles{end+1} = allesopeenhoop(varin(l));
%         end
%     else
%         alles = varin;
%     end
% end